'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ManageBidchargeCtrl
 * @description
 * # ManageBidchargeCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ManageBidchargeCtrl', function ($scope, openApi, Util, $location, $routeParams, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
        $scope.choosePeople = function () {
            var relModuleObj = {
                name: "ManageBidchargeCtrl",
                selectTab: "deposit_select_project",
                selectTabContent: "工程名称"
            };
            Util.savaParamForReview($scope.param, id);
            Util.savaDataforsearch(relModuleObj);

            $location.path("finance/choosepeople")
        };
        $scope.submit = function (operationId) {

            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.bidCharge;
            options.param = angular.copy($scope.param, {});
            options.param["formBidApply.formId"] = options.param["formBidApply.formId"] || options.param.formBidApply.formId || "";
            delete options.param.formBidApply
            FormSubmit.submit(options,$scope);
        };
        $scope.validate = function () {
            if (!$scope.param.projectName) {
                Util.Toast("请选择工程名称");
                return;
            }
            if (!$scope.param.userName) {
                Util.Toast("请输入交款人");
                return;
            }
            if (!$scope.param.amount) {
                if ($scope.param.amount !== 0) {
                    Util.Toast("请输入本次收款金额");
                    return;
                }
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
            });
        };
        // 初始化
        init();
    });